﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Telerik.Web.Mvc;
using ProjectManagement.Models;
using Projectmanagement.Utl;
using Projectmanagement.Entity;

namespace Projectmanagement.Controllers
{
    public class CityController : Controller
    {
        //
        // GET: /City/

        public ActionResult Index()
        {
            return View();
        }
        [GridAction]
        public ActionResult _SelectIndex(int? conferenceid)
        {
            return View(new GridModel(DQ.GetCity(conferenceid)));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _SaveAjaxEditing(int id, int? conferenceid)
        {
            string Cotents = String.IsNullOrWhiteSpace(Request["Contents"]) ? null : Request["Contents"].Trim();

            var item = CH.GetDataByID<City>(id);
            if (TryUpdateModel(item))
            {
                //if (item.CountryID != null)
                //{
                //    var country = CH.DB.Countrys.Find(item.CountryID);
                //    if (country != null)
                //    {
                //        item.CountryID = country.ID;
                //    }
                //}
                item.CountryID = conferenceid;
                CH.Edit<City>(item);

                
            }
            return View(new GridModel(DQ.GetCity(conferenceid)));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _InsertAjaxEditing(int? conferenceid)
        {
            var item = new City();
            //string Cotents = String.IsNullOrEmpty(Request["Contents"]) ? null : Request["Contents"].Trim();
            if (TryUpdateModel(item))
            {
               
               
                    //var country = CH.DB.Countrys.Find(item.CountryID);
                    //if (country != null)
                    //{
                item.CountryID = conferenceid;
                    //}

                    CH.Create<City>(item);
            }
            return View(new GridModel(DQ.GetCity(conferenceid)));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _DeleteAjaxEditing(int id, int? conferenceid)
        {
            CH.Delete<City>(id);
            return View(new GridModel(DQ.GetCity(conferenceid)));
        }

    }
}
